import type { EventHandler, EventHandlerRequest } from 'h3'
import type { Table } from 'dexie';
import Dexie from 'dexie';

// export const defineWrappedResponseHandler = <T extends EventHandlerRequest, D> (
//   handler: EventHandler<T, D>,
// ): EventHandler<T, D> =>
//     defineEventHandler<T>(async (event) => {
//       try {
//         const response = await handler(event)
//         return { response }
//       }
//       catch (err) {
//       // Error handling
//         return { err }
//       }
//     })
// example for Dexie
export interface Friend {
  id?: number;
  name: string;
  age: number;
}

export class MySubClassedDexie extends Dexie {
  // 'friends' is added by dexie when declaring the stores()
  // We just tell the typing system this is the case
  friends!: Table<Friend>;

  constructor() {
    super('myDatabase');
    this.version(1).stores({
      friends: '++id, name, age', // Primary key and indexed props
    });
  }
}

export const db = new MySubClassedDexie();
